﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;
using System.Data;

namespace FubiManger.Logistics
{
    partial class LogForm : Smobiler.Core.Controls.MobileForm
    {
        public LogForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        /// <summary>
        /// 商户ID
        /// </summary>
        public string merchantid { get; set; }
        public string adminid { get; set; }
        public string nickname { get; set; }
        List<ms_order> ordlist = new List<ms_order>();
        private void tbmenu_ToolbarItemClick(object sender, ToolbarClickEventArgs e)
        {
            switch (e.Name)
            {
                case "user":
                    LoguserForm frm = new LoguserForm();
                    frm.adminid = adminid;//ID
                    frm.nickname = nickname;//名称
                    this.Form.Show(frm, true,(obj,args)=> {
                        tbmenu.SelectedIndex = 0;
                    });
                    break;
            }
        }
        /// <summary>
        /// 订单刷新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lvord_Refresh(object sender, EventArgs e)
        {
            btnlog.ForeColor = System.Drawing.Color.FromArgb(207, 29, 32);
            btnlog.BorderColor = System.Drawing.Color.FromArgb(207, 29, 32);
            btnlog1.ForeColor = System.Drawing.Color.DimGray;
            btnlog1.BorderColor = System.Drawing.Color.Transparent;
            ordlist = orderDal.Querylog(merchantid, "3");
            Getorder(ordlist);
        }

        private void LogForm_Load(object sender, EventArgs e)
        {

            ordlist = orderDal.Querylog(merchantid, "3");
            Getorder(ordlist);
        }
        /// <summary>
        /// 刷新
        /// </summary>
        public void Refsh()
        {
            btnlog.ForeColor = System.Drawing.Color.FromArgb(207, 29, 32);
            btnlog.BorderColor = System.Drawing.Color.FromArgb(207, 29, 32);
            btnlog1.ForeColor = System.Drawing.Color.DimGray;
            btnlog1.BorderColor = System.Drawing.Color.Transparent;
            ordlist = orderDal.Querylog(merchantid, "3");
            Getorder(ordlist);
        }
        /// <summary>
        /// 获取订单
        /// </summary>
        private void Getorder(List<ms_order> ordlist)
        {

            if (lvord.Rows.Count > 0)
                lvord.Rows.Clear();
            DataTable table = new DataTable();
            table.Columns.Add("nickname");
            table.Columns.Add("ordid");
            table.Columns.Add("ordsn");
            table.Columns.Add("time");
            table.Columns.Add("disksn");
            table.Columns.Add("u_sage");
            table.Columns.Add("is_online");
            table.Columns.Add("status");
            for (int i = 0; i < ordlist.Count; i++)
            {
                string nickname = "";
                if (ordlist[i].user_tel.Length == 11)
                    nickname = ordlist[i].user_tel.Substring(0, 3) + "****" + ordlist[i].user_tel.Substring(7, 4);
                table.Rows.Add(nickname, ordlist[i].id, ordlist[i].order_sn, ordlist[i].add_time, ordlist[i].orderdisksn, ordlist[i].u_sage, ordlist[i].is_online, ordlist[i].status);
            }
            lvord.DataSource = table;
            lvord.DataBind();
        }
        /// <summary>
        /// 待发货
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnlog_Press(object sender, EventArgs e)
        {
            btnlog.ForeColor = System.Drawing.Color.FromArgb(207, 29, 32);
            btnlog.BorderColor= System.Drawing.Color.FromArgb(207, 29, 32);
            btnlog1.ForeColor = System.Drawing.Color.DimGray;
            btnlog1.BorderColor = System.Drawing.Color.Transparent;
            ordlist = orderDal.Querylog(merchantid, "3");
            Getorder(ordlist);
        }
        /// <summary>
        /// 已发货
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnlog1_Press(object sender, EventArgs e)
        {
            btnlog1.ForeColor = System.Drawing.Color.FromArgb(207, 29, 32);
            btnlog1.BorderColor = System.Drawing.Color.FromArgb(207, 29, 32);
            btnlog.ForeColor = System.Drawing.Color.DimGray;
            btnlog.BorderColor = System.Drawing.Color.Transparent;
            ordlist = orderDal.Querylog(merchantid, "5");
            Getorder(ordlist);
        }
    }
}